import { RegisterComponent } from '@feng3d/ecs';
import { Component3D, Mesh3D } from 'feng3d-three';
import { VertexTangentsHelper } from '../thirdparty/three/imports';

declare module '@feng3d/ecs'
{
    interface ComponentMap { VertexTangentsHelper3D: VertexTangentsHelper3D; }
}

/**
 * 包装`three`中`VertexNormalsHelper`。
 */
@RegisterComponent({ name: 'VertexTangentsHelper3D' })
export class VertexTangentsHelper3D extends Component3D
{
    _helper: VertexTangentsHelper;

    object: Mesh3D;
    size?: number;
    hex?: number;

    init()
    {
        super.init();

        // 更新全局矩阵
        this.object._mesh.updateWorldMatrix(true, false);

        this._helper = new VertexTangentsHelper(this.object._mesh, this.size, this.hex);

        this._entity._group.add(this._helper);
    }

    destroy(): void
    {
        this._entity._group.remove(this._helper);

        this._helper.dispose();
        this._helper = null;

        super.destroy();
    }

    update()
    {
        this._helper.update();
    }
}
